﻿using System;
using System.Collections.Generic;
using System.Text;

namespace HZ.Supervise.DAL
{
   public class DAL_Stocks
    {
       /// <summary>
        /// 医院、企业库存汇总
       /// </summary>
       /// <param name="sqlwhere"></param>
       /// <param name="currentpage"></param>
       /// <param name="pagesize"></param>
       /// <param name="totalrecord"></param>
       /// <returns></returns>
       public static System.Data.DataTable GetHosComTotalStock(string sqlwhere, int currentpage, int pagesize, out int totalrecord)
       {
           StringBuilder sql = new StringBuilder();
           sql.Append(string.Format("select * from View_HosComTotalStock where 1=1 {0}", sqlwhere));
           HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(sql.ToString(), pagesize);
           des.CurrentPage = currentpage;
            totalrecord = des.TotalCount;
           return des.GetSpecailPage();
       }
       /// <summary>
       /// 医院库存
       /// </summary>
       /// <param name="sqlwhere"></param>
       /// <param name="currentpage"></param>
       /// <param name="pagesize"></param>
       /// <param name="totalrecord"></param>
       /// <returns></returns>
       public static System.Data.DataTable GetHosTotalStock(string goodsid ,string sqlwhere, int currentpage, int pagesize, out int totalrecord)
       {
           StringBuilder sql = new StringBuilder();
           sql.Append(string.Format("select '{0}' ProcureCatalogID,TB_Hospital.HospitalID,HospitalName,Areaid,ISNULL(HospitalTotalStock,0) HospitalTotalStock  from TB_Hospital left join (select  TB_Hospital.HospitalID,ISNULL(SUM(Stock),0) HospitalTotalStock from TB_Hospital left join  TB_HospitalProcureCatalogCompanyPs on TB_HospitalProcureCatalogCompanyPs.HospitalID=TB_Hospital.HospitalID WHERE ProcureCatalogID='{0}' group by TB_Hospital.HospitalID,ProcureCatalogID) HospitalTotalStock on TB_Hospital.HospitalID=HospitalTotalStock.HospitalID where 1=1 {1}",goodsid, sqlwhere));
           HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(sql.ToString(), pagesize);
           des.CurrentPage = currentpage;
           totalrecord = des.TotalCount;
           return des.GetSpecailPage();
       }
       /// <summary>
       /// 企业库存
       /// </summary>
       /// <param name="sqlwhere"></param>
       /// <param name="currentpage"></param>
       /// <param name="pagesize"></param>
       /// <param name="totalrecord"></param>
       /// <returns></returns>
       public static System.Data.DataTable GetComTotalStock(string sqlwhere, int currentpage, int pagesize, out int totalrecord)
       {
           StringBuilder sql = new StringBuilder();
           sql.Append(string.Format("select * from View_ComTotalStock where 1=1 {0}", sqlwhere));
           HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(sql.ToString(), pagesize);
           des.CurrentPage = currentpage;
           totalrecord = des.TotalCount;
           return des.GetSpecailPage();
       }
       /// <summary>
       /// 医院库存明细
       /// </summary>
       /// <param name="sqlwhere"></param>
       /// <param name="currentpage"></param>
       /// <param name="pagesize"></param>
       /// <param name="totalrecord"></param>
       /// <returns></returns>
       public static System.Data.DataTable GetHosTotalStockDetail(string sqlwhere, int currentpage, int pagesize, out int totalrecord)
       {
           StringBuilder sql = new StringBuilder();
           sql.Append(string.Format("select * from View_HospitalProcureCatalogCompanyPs where 1=1 {0}", sqlwhere));
           HZ.Data.PageDescribe des = new HZ.Data.PageDescribe(sql.ToString(), pagesize);
           des.CurrentPage = currentpage;
           totalrecord = des.TotalCount;
           return des.GetSpecailPage();
       }
    }
}
